You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improves the error message returned when an index has an empty mapping. This change makes the error clearer and more actionable for users while preserving the existing behavior. Unit tests have been updated to verify the new error message.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.
The pattern detection logic treats a single string containing a comma (e.g., "index1,index2") as a non-pattern, but OpenSearch interprets comma-separated values within a single string as multiple indices. This mismatch causes the error message to omit the "compatible mapping" hint when it should be included, misleading users who pass comma-separated index names as a single argument.
|| Arrays.stream(exprs)
.filter(e -> e != null)
.anyMatch(
e ->
e.contains("*")
|| e.contains("?")
|| e.startsWith("<")
|| e.startsWith("-")
|| e.equals("_all"));
The pattern detection logic treats a leading hyphen (-) as a wildcard pattern indicator, but in OpenSearch index expressions, a leading hyphen denotes exclusion (e.g., index,-excluded). This can cause false positives when checking for patterns. Consider removing the e.startsWith("-") condition or refining the logic to distinguish between exclusion syntax and actual pattern indicators.*
Why: The suggestion correctly identifies that e.startsWith("-") may cause false positives in pattern detection. In OpenSearch, a leading hyphen indicates exclusion syntax rather than a wildcard pattern. Removing this check would improve the accuracy of pattern detection, though the impact is moderate since exclusion syntax is less commonly used alone.
Avoid false pattern detection for hyphenated names
The pattern detection logic treats a leading hyphen (-) as a wildcard pattern indicator, but this conflicts with date-based index names (e.g., logs-2024-01-01) which are common and not patterns. Consider checking for exclusion syntax more precisely (e.g., -index without other characters) or removing this check to avoid false positives.
Why: The suggestion correctly identifies that e.startsWith("-") can cause false positives for date-based index names like logs-2024-01-01. However, the check is intended to detect exclusion patterns (e.g., -excluded_index), which are valid OpenSearch syntax. The suggestion to remove this check entirely may miss legitimate exclusion patterns, but the concern about false positives is valid and warrants careful consideration.
The pattern detection logic treats any expression starting with - as a pattern, but - is used for exclusions in multi-index patterns (e.g., index,-excluded). A single expression starting with - (like -myindex) is invalid and should not be classified as a pattern requiring the "compatible mapping" hint.*
Why: The suggestion correctly identifies that a single expression starting with - (like -myindex) is invalid and shouldn't trigger the "compatible mapping" hint. However, the logic exprs.length > 1 already handles multi-index patterns where exclusions are valid, so removing the e.startsWith("-") check is appropriate for single-expression cases.
Catching and re-throwing ErrorReport is unnecessary since ErrorReport extends RuntimeException. The existing catch block for generic Exception will not catch ErrorReport anyway due to the order. Remove this redundant catch block to simplify the exception handling flow.
Why: The catch block for ErrorReport appears redundant since it only re-throws the exception. However, it serves to preserve the specific ErrorReport type before the generic Exception handler wraps it in IllegalStateException. Removing it would change exception handling behavior, though the impact is minor since ErrorReport extends RuntimeException.
Low
Fix pattern detection for multi-index queries
The pattern detection logic treats a comma within a single string as a pattern indicator, but commas are also used to separate multiple index names in a single argument. This can cause false positives where legitimate multi-index queries without wildcards are incorrectly flagged as patterns. Consider checking if the array contains multiple elements OR if any single element contains pattern syntax.
Why: The suggestion identifies a potential issue where exprs.length > 1 could help distinguish multi-index queries, but the current logic already handles commas within strings as pattern indicators (which is correct per OpenSearch syntax). The test at line 310-314 validates this behavior. The suggestion may introduce unintended changes to the error message logic without clear benefit.
The pattern detection logic may incorrectly classify indices with hyphens in their names (e.g., my-index) as patterns because it checks e.startsWith("-"). This check is intended for exclusion patterns but will match any index name containing a leading hyphen. Consider checking for exclusion syntax more precisely or documenting this behavior.
Why: The suggestion correctly identifies a critical bug where e.startsWith("-") would incorrectly classify normal index names like my-index as patterns. The improved code adds a check to distinguish between exclusion patterns (e.g., -excluded*) and regular hyphenated names, preventing false positives that would show incorrect error messages to users.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Improves the error message returned when an index has an empty mapping. This change makes the error clearer and more actionable for users while preserving the existing behavior. Unit tests have been updated to verify the new error message.
Related Issues
Resolves #[4872]
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.